
package com.hlkj.pay.enums;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import com.hlkj.pay.app.merchant.ext.MerchantExtConstant;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * @author HlpayTeam
 * @date 2024/09/12 15:27
 */
public interface PayOrderEnums {

    @Getter
    enum PAY_ORDER_STATUS
    {

        // 订单状态，订单状态，1=初始化，2=支付中，3=支付成功，4=已撤销，5=订单关闭 6=订单关闭中 7=支付失败
        INIT(1, "初始化"), PAYING(2, "支付中"), SUCCESS(3, "支付成功"), CANCEL(4, "已撤销"), CLOSEING(6, "订单关闭中"), CLOSE(5, "订单关闭"), FAIL(7, "支付失败"),

        ;

        /**
         * 错误码
         */
        private Integer code;

        /**
         * 错误提示
         */
        private String msg;

        PAY_ORDER_STATUS(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static PAY_ORDER_STATUS from(Integer key) {
            PAY_ORDER_STATUS[] values = PAY_ORDER_STATUS.values();
            for (PAY_ORDER_STATUS deliveryType : values) {
                if (deliveryType.getCode().equals(key)) {
                    return deliveryType;
                }
            }
            return PAY_ORDER_STATUS.INIT;
        }
    }

    @Getter
    enum ORDER_REFUND_STATUS
    {

        // 1 未退款 2 退款中 3 部分退款 4 退款完成 5 退款失败
        NO_REFUND(1, "未退款"),
        REFUNDING(2, "退款中"),
        PART_REFUND(3, "部分退款"),
        REFUND(4, "退款完成"),
        FAIL(5, "退款失败"),

        ;

        /**
         * 错误码
         */
        private Integer code;

        /**
         * 错误提示
         */
        private String msg;

        ORDER_REFUND_STATUS(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static ORDER_REFUND_STATUS from(Integer key) {
            ORDER_REFUND_STATUS[] values = ORDER_REFUND_STATUS.values();
            for (ORDER_REFUND_STATUS deliveryType : values) {
                if (deliveryType.getCode().equals(key)) {
                    return deliveryType;
                }
            }
            return ORDER_REFUND_STATUS.NO_REFUND;
        }
    }

    @Getter
    enum REFUND_STATUS
    {

        // 1 初始化 2 退款中 3 退款完成 4 退款失败
        INIT(1, "初始化"),
        REFUNDING(2, "退款中"),
        REFUND(3, "退款完成"),
        FAIL(4, "退款失败"),

        ;

        /**
         * 错误码
         */
        private Integer code;

        /**
         * 错误提示
         */
        private String msg;

        REFUND_STATUS(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static REFUND_STATUS from(Integer key) {
            REFUND_STATUS[] values = REFUND_STATUS.values();
            for (REFUND_STATUS deliveryType : values) {
                if (deliveryType.getCode().equals(key)) {
                    return deliveryType;
                }
            }
            return REFUND_STATUS.INIT;
        }
    }

    @Getter
    enum REFUND_APPLY_STATUS
    {

        // 1 未退款 2 退款中 3 部分退款 4 退款完成
        WAIT_APPROVE(1, "待审核"), APPROVE(2, "审核通过"), REJECT(3, "审核拒绝"),

        ;

        /**
         * 错误码
         */
        private Integer code;

        /**
         * 错误提示
         */
        private String msg;

        REFUND_APPLY_STATUS(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static REFUND_APPLY_STATUS from(Integer key) {
            REFUND_APPLY_STATUS[] values = REFUND_APPLY_STATUS.values();
            for (REFUND_APPLY_STATUS deliveryType : values) {
                if (deliveryType.getCode().equals(key)) {
                    return deliveryType;
                }
            }
            return REFUND_APPLY_STATUS.WAIT_APPROVE;
        }
    }

    @Getter
    enum ORDER_NO_TYPE
    {

        // 1 未退款 2 退款中 3 部分退款 4 退款完成
        ORDER("D", "订单号"),
        REFUND("T", "退款单号"),
        REFUND_APPLY("TA", "退款申请号"),
        RECHARGE_APPLY("C", "充值申请号"),
        PAYMENT_APPLY("P", "付款申请号"),
        CASH("T", "提现申请号"),
        CASHIER("Y", "收银台单号"),
        TRANSFER("Z", "转账订单"),
        WITHDRAW("W", "提现订单"),

        ;

        /**
         * 错误码
         */
        private String code;

        /**
         * 错误提示
         */
        private String msg;

        ORDER_NO_TYPE(String code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static ORDER_NO_TYPE from(String key) {
            ORDER_NO_TYPE[] values = ORDER_NO_TYPE.values();
            for (ORDER_NO_TYPE deliveryType : values) {
                if (deliveryType.getCode().equals(key)) {
                    return deliveryType;
                }
            }
            return ORDER_NO_TYPE.ORDER;
        }
    }

    @Getter
    enum PAY_DATA_TYPE
    {

        // 1 未退款 2 退款中 3 部分退款 4 退款完成
        URL("url", "订单号"), DATA("data", "数据体"), NONE("none", "无")

        ;

        /**
         * 错误码
         */
        private String code;

        /**
         * 错误提示
         */
        private String msg;

        PAY_DATA_TYPE(String code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static PAY_DATA_TYPE from(String key) {
            PAY_DATA_TYPE[] values = PAY_DATA_TYPE.values();
            for (PAY_DATA_TYPE deliveryType : values) {
                if (deliveryType.getCode().equals(key)) {
                    return deliveryType;
                }
            }
            return PAY_DATA_TYPE.DATA;
        }
    }

    @Getter
    enum ORDER_STATUS_TYPE
    {

        PAY_ORDER_STATUS(1, "订单支付成功"),
        REFUND_STATUS(2, "退款成功"),
        ORDER_CLOSE(3, "订单关闭"),
        PAYMENT_ORDER_STATUS(4, "转账订单成功"),
        MERCHANT_ACCESS_STATUS(5,"商户进件审核完成"),
        MERCHANT_ACCESS_SETTLE_STATUS(6, "商户结算完成"),
        FUND_ORDER_STATUS(7, "分账订单完成"),
        TRANSFER_ORDER_STATUS(8, "转账订单"),
        WITHDRAW_ORDER_STATUS(9, "提现订单"),
        SUBSIDY_ORDER_STATUS(9, "营销订单"),


        ;

        /**
         * 错误码
         */
        private Integer code;

        /**
         * 错误提示
         */
        private String msg;

        ORDER_STATUS_TYPE(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static ORDER_STATUS_TYPE from(Integer key) {
            ORDER_STATUS_TYPE[] values = ORDER_STATUS_TYPE.values();
            for (ORDER_STATUS_TYPE deliveryType : values) {
                if (deliveryType.getCode().equals(key)) {
                    return deliveryType;
                }
            }
            return ORDER_STATUS_TYPE.PAY_ORDER_STATUS;
        }
    }

    @Getter
    enum ORDER_STATISTICS_TYPE
    {

        // 统计维度 1 商户维度 2 支付方式 3 APPID 4 通道编码
        SN(1, "商户维度"), PAY_TYPE(2, "支付方式"), APPID(3, "APPID"), MCH_CHANNEL_CODE(4, "通道编码"),CHANNEL_CODE(5, "渠道编码"),AUT_CODE(6, "AUT编码"),

        ;

        /**
         * 错误码
         */
        private Integer code;

        /**
         * 错误提示
         */
        private String msg;

        ORDER_STATISTICS_TYPE(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static ORDER_STATISTICS_TYPE from(Integer key) {
            ORDER_STATISTICS_TYPE[] values = ORDER_STATISTICS_TYPE.values();
            for (ORDER_STATISTICS_TYPE deliveryType : values) {
                if (deliveryType.getCode().equals(key)) {
                    return deliveryType;
                }
            }
            return ORDER_STATISTICS_TYPE.SN;
        }
    }

    @Getter
    enum STATISTICS_TYPE
    {

        SUBMIT_ORDER(1, "提交订单"), PAY_ORDER(2, "支付订单"), REFUND_ORDER(3, "订单退款"),

        ;

        /**
         * 错误码
         */
        private Integer code;

        /**
         * 错误提示
         */
        private String msg;

        STATISTICS_TYPE(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static PayOrderEnums.STATISTICS_TYPE from(Integer key) {
            PayOrderEnums.STATISTICS_TYPE[] values = PayOrderEnums.STATISTICS_TYPE.values();
            for (PayOrderEnums.STATISTICS_TYPE deliveryType : values) {
                if (deliveryType.getCode().equals(key)) {
                    return deliveryType;
                }
            }
            return PayOrderEnums.STATISTICS_TYPE.SUBMIT_ORDER;
        }
    }

    @Getter
    enum PAY_ORDER_FUND_STATUS
    {

        INIT(1, "初始化"),
        WAIT_FUND(2, "待分账"),
        FUNDING(3, "分账中"),
        SUCCESS(4, "已分账"),
        FAIL(5, "分账失败"),
        CLOSE(6, "已完结"),
        REFUND(7, "已退款"),
        REFUNDING(8, "分账退款中"),
        REFUND_FAIL(9, "分账退款失败"),


        ;

        /**
         * 错误码
         */
        private Integer code;

        /**
         * 错误提示
         */
        private String msg;

        PAY_ORDER_FUND_STATUS(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static PAY_ORDER_FUND_STATUS from(Integer key) {
            PAY_ORDER_FUND_STATUS[] values = PAY_ORDER_FUND_STATUS.values();
            for (PAY_ORDER_FUND_STATUS deliveryType : values) {
                if (deliveryType.getCode().equals(key)) {
                    return deliveryType;
                }
            }
            return PAY_ORDER_FUND_STATUS.INIT;
        }
    }


    @Getter
    enum PAY_ORDER_FUND_AMOUNT_STATUS
    {

        NOT_FUND(1, "未分账"),
        PART_FUND(2, "部分分账"),
        SUCCESS(3, "分账完成"),

        ;

        /**
         * 错误码
         */
        private Integer code;

        /**
         * 错误提示
         */
        private String msg;

        PAY_ORDER_FUND_AMOUNT_STATUS(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static PAY_ORDER_FUND_AMOUNT_STATUS from(Integer key) {
            PAY_ORDER_FUND_AMOUNT_STATUS[] values = PAY_ORDER_FUND_AMOUNT_STATUS.values();
            for (PAY_ORDER_FUND_AMOUNT_STATUS deliveryType : values) {
                if (deliveryType.getCode().equals(key)) {
                    return deliveryType;
                }
            }
            return PAY_ORDER_FUND_AMOUNT_STATUS.NOT_FUND;
        }
    }

    @Getter
    enum FUND_PROCESS_TYPE
    // 分账类型 ，0或空=无分账，1=实时分账，2=延时分账，3=商户 预设默认分账
    {

        NO(0, "无分账"),
        REAL_TIME(1, "实时分账"),
        DELAY_TIME(2, "延时分账"),
        MERCHANT(3, "商户 预设默认分账"),

        ;

        /**
         * 错误码
         */
        private Integer code;

        /**
         * 错误提示
         */
        private String msg;

        FUND_PROCESS_TYPE(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static FUND_PROCESS_TYPE from(Integer key) {
            FUND_PROCESS_TYPE[] values = FUND_PROCESS_TYPE.values();
            for (FUND_PROCESS_TYPE deliveryType : values) {
                if (deliveryType.getCode().equals(key)) {
                    return deliveryType;
                }
            }
            return FUND_PROCESS_TYPE.NO;
        }
    }


    @Getter
    enum PAY_ORDER_SUBSIDY_STATUS
    {

        INIT(0,"初始化"),
        PROCESSING(1, "处理中"),
        SUCCESS(2, "成功"),
        FAIL(3, "失败"),

        ;

        /**
         * 错误码
         */
        private Integer code;

        /**
         * 错误提示
         */
        private String msg;

        PAY_ORDER_SUBSIDY_STATUS(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static PAY_ORDER_SUBSIDY_STATUS from(Integer key) {
            PAY_ORDER_SUBSIDY_STATUS[] values = PAY_ORDER_SUBSIDY_STATUS.values();
            for (PAY_ORDER_SUBSIDY_STATUS subsidyType : values) {
                if (subsidyType.getCode().equals(key)) {
                    return subsidyType;
                }
            }
            return PAY_ORDER_SUBSIDY_STATUS.PROCESSING;
        }
    }

    /**
     * 营销类型
     */
    @Getter
    enum PAY_ORDER_SUBSIDY_TYPE
    {
        CUSTOM_REDUCTION(1,"自定义金额立减"),
        CUSTOM_ALLOWANCE(2, "自定义金额补贴"),
        CASH_COUPON(3, "代金券"),
        FULL_DISCOUNT_COUPON(4, "满减券"),

        ;

        /**
         * 错误码
         */
        private Integer code;

        /**
         * 错误提示
         */
        private String msg;

        PAY_ORDER_SUBSIDY_TYPE(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static PAY_ORDER_SUBSIDY_TYPE from(Integer key) {
            PAY_ORDER_SUBSIDY_TYPE[] values = PAY_ORDER_SUBSIDY_TYPE.values();
            for (PAY_ORDER_SUBSIDY_TYPE subsidyType : values) {
                if (subsidyType.getCode().equals(key)) {
                    return subsidyType;
                }
            }
            return PAY_ORDER_SUBSIDY_TYPE.CUSTOM_REDUCTION;
        }
    }


    @Getter
    enum SYSTEM_PROCESS_TYPE
    // 系统处理类型 ，0 渠道自动处理 1 系统处理 2 商户自行请求
    {

        CHANNEL(0, "渠道自动处理"), SYSTEM(1, "系统处理"), MERCHANT(2, "商户自行请求"),

        ;

        /**
         * 错误码
         */
        private Integer code;

        /**
         * 错误提示
         */
        private String msg;

        SYSTEM_PROCESS_TYPE(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static SYSTEM_PROCESS_TYPE from(Integer key) {
            SYSTEM_PROCESS_TYPE[] values = SYSTEM_PROCESS_TYPE.values();
            for (SYSTEM_PROCESS_TYPE deliveryType : values) {
                if (deliveryType.getCode().equals(key)) {
                    return deliveryType;
                }
            }
            return SYSTEM_PROCESS_TYPE.CHANNEL;
        }
    }

    @Getter
    enum CHANNEL_FUND_PROCESS_TYPE
    // 分账类型 ，0或空=无分账，1=实时分账，2=延时分账，3=商户 预设默认分账
    {

        HEEPAY(MerchantExtConstant.CHANNEL_HEEPAY, Arrays.asList(SYSTEM_PROCESS_TYPE.SYSTEM,SYSTEM_PROCESS_TYPE.CHANNEL), false),
        EASYPAY(MerchantExtConstant.CHANNEL_EASY_PAY, Arrays.asList(SYSTEM_PROCESS_TYPE.SYSTEM), true),
        WXPAY(MerchantExtConstant.CHANNEL_WX_PAY, Arrays.asList(SYSTEM_PROCESS_TYPE.SYSTEM), false),
        ALIPAY_ZFT(MerchantExtConstant.CHANNEL_ALI_PAY_ZFT, Arrays.asList(SYSTEM_PROCESS_TYPE.SYSTEM), false),

        ;

        /**
         * 错误码
         */
        private String channelCode;

        /**
         * 错误提示
         */
        private List<SYSTEM_PROCESS_TYPE> systemProcessTypes;

        /**
         * 是否需要手续费费率
         */
        private boolean needFee;

        CHANNEL_FUND_PROCESS_TYPE(String channelCode, List<SYSTEM_PROCESS_TYPE> systemProcessTypes, boolean needFee) {
            this.channelCode = channelCode;
            this.systemProcessTypes = systemProcessTypes;
            this.needFee = needFee;
        }

        public static CHANNEL_FUND_PROCESS_TYPE from(String channelCode) {
            CHANNEL_FUND_PROCESS_TYPE[] values = CHANNEL_FUND_PROCESS_TYPE.values();
            for (CHANNEL_FUND_PROCESS_TYPE deliveryType : values) {
                if (deliveryType.getChannelCode().equals(channelCode)) {
                    return deliveryType;
                }
            }
            return null;
        }
    }

    @Getter
    enum PAY_ORDER_TYPE
    {

        // 订单状态，订单状态，1=初始化，2=支付中，3=支付成功，4=已撤销，5=订单关闭 6=订单关闭中 7=支付失败
        MERCHANT(0, "商户订单"),
        RECHARGE(1, "充值订单"),
        QR(3, "码牌订单"),
        CRASH(4, "收银台订单"),
        RECEIPT(5, "收款单"),

        ;

        /**
         * 错误码
         */
        private Integer code;

        /**
         * 错误提示
         */
        private String msg;

        PAY_ORDER_TYPE(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static PAY_ORDER_TYPE from(Integer key) {
            PAY_ORDER_TYPE[] values = PAY_ORDER_TYPE.values();
            for (PAY_ORDER_TYPE deliveryType : values) {
                if (deliveryType.getCode().equals(key)) {
                    return deliveryType;
                }
            }
            return PAY_ORDER_TYPE.MERCHANT;
        }
    }


    @Getter
    enum PAY_FUNCTION_SENCE_TYPE
    {

        // 功能产品场景 1=分账 2=产品
        SHARE(1, "分账"),
        PRODUCT(2, "产品"),

        ;

        /**
         * 错误码
         */
        private Integer code;

        /**
         * 错误提示
         */
        private String msg;

        PAY_FUNCTION_SENCE_TYPE(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static PAY_FUNCTION_SENCE_TYPE from(Integer key) {
            PAY_FUNCTION_SENCE_TYPE[] values = PAY_FUNCTION_SENCE_TYPE.values();
            for (PAY_FUNCTION_SENCE_TYPE type : values) {
                if (type.getCode().equals(key)) {
                    return type;
                }
            }
            return PAY_FUNCTION_SENCE_TYPE.PRODUCT;
        }
    }


    @Getter
    enum PAY_ORDER_RECEIVE_STATUS
    {

        CLOSED(0, "已关闭"),
        NOT_PAY(1, "未收款"),
        PAY(2, "已收款"),
        FINISH(3, "已完成"),

        ;

        /**
         * 错误码
         */
        private Integer code;

        /**
         * 错误提示
         */
        private String msg;

        PAY_ORDER_RECEIVE_STATUS(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public static PAY_ORDER_RECEIVE_STATUS from(Integer key) {
            PAY_ORDER_RECEIVE_STATUS[] values = PAY_ORDER_RECEIVE_STATUS.values();
            for (PAY_ORDER_RECEIVE_STATUS deliveryType : values) {
                if (deliveryType.getCode().equals(key)) {
                    return deliveryType;
                }
            }
            return PAY_ORDER_RECEIVE_STATUS.CLOSED;
        }
    }

}
